package functions;

import main.ContingencyTable;

public class GiniIndexFunction extends GeneralFunction {

	public GiniIndexFunction(String name) {
		super(name);
	}

	@Override
	public double calculate(ContingencyTable t) {
		return (t.f1p() / t.N())
				* (sq(t.f11() / t.f1p()) + sq(t.f10() / t.f1p()))
				- sq(t.fp1() / t.N()) + (t.f0p() / t.N())
				* (sq(t.f01() / t.f0p()) + sq(t.f00() / t.f0p()))
				- sq(t.fp0() / t.N());
	}

	double sq(double a) {
		return a * a;
	}
}
